﻿@model Fap.AspNetCore.ViewModel.JqGridViewModel
<title>
    <fap-multilang default-content="薪资套" lang-key="payset"></fap-multilang>
</title>

<link href="~/Content/css/codemirror/codemirror.css" rel="stylesheet" />
<link href="~/Content/css/codemirror/theme/xq-light.css" rel="stylesheet" />

<div class="row">
    <div class="col-xs-12">
        <div class="widget-box">
            <div class="widget-header widget-header-flat">
                <h4 class="widget-title">
                    <fap-multilang default-content="薪资套" lang-key="payset"></fap-multilang>
                </h4>
                <div class="widget-toolbar">
                    <a href="#" data-action="fullscreen" class="orange2">
                        <i class="ace-icon fa fa-expand"></i>
                    </a>
                </div>
                <div class="widget-toolbar">
                    <fap-button id="btnPaycaseAuthority" btn-tag="link" content="权限" icon-before="fa fa-cog blue" class-name="info"></fap-button>
                </div>
                <div class="widget-toolbar">
                    <fap-button id="btnPayItem" btn-tag="link" content="薪资项" icon-before="fa fa-list-alt blue" class-name="info"></fap-button>
                    <fap-button id="btnEmployee" btn-tag="link" content="员工" icon-before="fa fa-users blue" class-name="info"></fap-button>
                    <fap-button id="btnFormula" btn-tag="link" content="公式" icon-before="fa fa-superscript blue" class-name="info"></fap-button>
                </div>
            </div>
            <div class="widget-body">
                <div class="widget-main">
                    <fap-grid id="paycase" grid-model="Model" auto-width="true"></fap-grid>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var scripts = [null, "/Content/js/jquery.bootstrap-duallistbox.js", "/Content/js/codemirror/codemirror.js", "/Content/js/codemirror/mode/sql/sql.js", null]
    $('.page-content-area').ace_ajax('loadScripts', scripts, function () {
        jQuery(function ($) {
            $(document).one('ajaxloadstart.page', function (e) {

            })
            //薪资项
            $("#btnPayItem").on(ace.click_event, function () {
                var rw = getSelectedRow("grid-paycase");
                if (rw == null) {
                    return;
                }
                let caseUid = rw.Fid;
                bootboxWindow($.lang("payitem", "薪资项"), basePath + "/Payroll/Manage/PayItem?caseUid=" + caseUid, {
                    add: {
                        label: $.lang("add", "新增"),
                        className: "btn-primary btn-link",
                        callback: function () {
                            AddPayItem(caseUid);
                            return false;
                        }
                    },
                    generate: {
                        label: $.lang("generate", "生成"),
                        className: "btn-primary btn-link",
                        callback: function () {
                            bootbox.confirm("提示：如果之前生成过薪资项，本次生成将会删掉之前的数据，确定生成?", function (result) {
                                if (result) {
                                    generatePayItem(caseUid);
                                }
                            });
                            return false;
                        }
                    },
                    payrollShow: {
                        label: $.lang("payroll_item", "薪资条项"),
                        className: "btn-primary btn-link",
                        callback: function () {
                            setPayrollItemShow(caseUid);
                            return false;
                        }
                    }
                })
            })
            //公式套包含员工条件
            $("#btnEmployee").on(ace.click_event, function () {
                var rw = getSelectedRow("grid-paycase");
                if (rw == null) {
                    return;
                }
                let caseUid = rw.Fid;
                bootboxWindow($.lang("paycase_condition", "设置薪资套员工条件"), basePath + "/Payroll/Manage/PayEmployee", {
                    add: {
                        label: $.lang("save_employee_condition", "保存员工条件"),
                        className: "btn-primary btn-link",
                        callback: function () {
                            savePaycaseCondition(caseUid);
                            return false;
                        }
                    },
                    initPayCase: {
                        label: $.lang("init_payset", "初始化薪资套员工"),
                        className: "btn-primary btn-link",
                        callback: function () {
                            initPaycaseEmployee(caseUid);
                            return false;
                        }
                    }
                }, { caseUid: caseUid }, function () {
                    loadPaycaseEmployee(caseUid);
                })
            })
            $("#btnFormula").on(ace.click_event, function () {
                var rw = getSelectedRow("grid-paycase");
                if (rw == null) {
                    return;
                }
                let tn = rw.TableName;
                bootboxWindow($.lang("paycase_formula", "薪资套公式"), basePath + "/Component/FormulaEditor", {
                    associate: {
                        label: $.lang("associate_set", "引用关联设置"),
                        className: "btn-primary btn-link",
                        callback: function () {
                            bootboxWindow($.lang("associate", "关联"), basePath + "/Component/EntityAssociate", null, { oriCode: "PayCenter", oriName: "薪资套" });
                            return false;
                        }
                    }
                }, { tableName: tn, mappingTable: "PayCenter" });
            })
            //权限
            $("#btnPaycaseAuthority").on(ace.click_event, function () {
                var rw = getSelectedRow("grid-paycase");
                if (rw == null) {
                    return;
                }
                let caseUid = rw.Fid;
                let caseName = rw.CaseName;
                bootboxWindow($.lang("paycase_authority", "薪资套权限"), basePath + "/Payroll/Manage/PayAuthority?caseUid=" + caseUid + "&caseName=" + caseName + "&menuUrl=~/Payroll/Manage/PaySet");
            })
        })
    })
</script>
